//Screen.cpp

#include "Screen.h"

Screen::Screen()
{
	m_oldBuff = m_buffer1;
	m_newBuff = m_buffer2;
	InitScreen();
}

void Screen::InitBuffer(char (*buffP)[SCR_HOR])
{
	for (int i=0; i < SCR_VER; ++i)
		for (int j=0; j < SCR_HOR; ++j)
			buffP[i][j] = ' ';
}

void Screen::InitScreen()
{
	InitBuffer(m_oldBuff);
	InitBuffer(m_newBuff);
}

bool Screen::set(int x, int y, char ch)
{
	if (isLegalPosition(x, y))
	{
		m_newBuff[y][x] = ch;
		return true;
	}
	else
		return false;
}

void Screen::printDiff()
{
	for (int i=0; i < SCR_VER; ++i)
		for (int j=0; j < SCR_HOR; ++j)
			if (m_newBuff[i][j] ^ m_oldBuff[i][j])
			{
				gotoxy(j, i);
				cout << m_newBuff[i][j];
			}
}

void Screen::swapPointersAndInitNewBuff()
{
	char (*tempBuffp)[SCR_HOR] = m_newBuff;

	m_newBuff = m_oldBuff;
	m_oldBuff = tempBuffp;
	InitBuffer(m_newBuff);
}

